/* set bookmark */
function setBookmark(){
	if(document.all){
		window.external.AddFavorite(location.href,document.title); 
	}else if(window.sidebar){
		window.sidebar.addPanel (document.title,location.href,'');
	}
	else if(window.chrome){
    	alert('dùng phím tắt ctrl+D để bookmark (Command+D cho macs) sau đó click Ok');
    } 	
}
/* set bookmark */

/* slideshow hot game */
var hotgame_record_index =   0;
var int_hotgame     =   null;
function auto_slideshow_hotgame(){
    var list_hotgame = $.makeArray($('.top-game .list-game'));
    if(list_hotgame.length <= 1){
        return;
    }
    if(hotgame_record_index > list_hotgame.length - 1){
        hotgame_record_index = 0;
    }
    $('.top-game .list-game').hide();
    $(list_hotgame[hotgame_record_index]).fadeIn(800);
    hotgame_record_index++;
    int_hotgame = setTimeout(function(){
        auto_slideshow_hotgame();
    },6500);
}
function slideshow_hotgame_next(){
    clearTimeout(int_hotgame);
    var list_hotgame = $.makeArray($('.top-game .list-game'));
    if(hotgame_record_index >= list_hotgame.length){
        hotgame_record_index = 0;
    }
    auto_slideshow_hotgame();
}
function slideshow_bestbuy_pre(){
    hotgame_record_index--;
	hotgame_record_index--;
    clearTimeout(int_hotgame);
    var list_hotgame = $.makeArray($('.top-game .list-game'));
    if(hotgame_record_index < 0){
        hotgame_record_index = 0;
    }
    auto_slideshow_hotgame();
}
/* end slideshow hot game */

/* load game hay nhat cho 1 danh muc khi click vao tab */
function loadHotgamebycategoryAjax(catid, current_li){
	var tab_class	=	'tab-block-' + catid;
	var gamelist_class	=	'home-block-' + catid;
	var li_tabs = $('.' + tab_class).find('li');
	$(li_tabs).each(function(index, el){
		if($(el).hasClass('active')){
			$(el).removeClass('active');
		}
	});
	$(current_li).addClass('active');
}
/* load game moi nhat cho 1 danh muc khi click vao tab */
function loadLastestgamebycategoryAjax(catid, current_li){
	var tab_class	=	'tab-block-' + catid;
	var gamelist_class	=	'home-block-' + catid;
	var li_tabs = $('.' + tab_class).find('li');
	$(li_tabs).each(function(index, el){
		if($(el).hasClass('active')){
			$(el).removeClass('active');
		}
	});
	$(current_li).addClass('active');
}
/* load game nhieu nguoi choi nhat cho 1 danh muc khi click vao tab */
function loadPopulargamebycategoryAjax(catid, current_li){
	var blockgame_class	=	'home-blockgame-' + catid;
	var tab_class	=	'tab-block-' + catid;
	var gamelist_class	=	'home-blockgame-' + catid;
	var layer_idname	=	'layerid-' + catid;
	
	show_screen_loader_ajax(gamelist_class, layer_idname);
	
	var li_tabs = $('.' + tab_class).find('li');
	$(li_tabs).each(function(index, el){
		if($(el).hasClass('active')){
			$(el).removeClass('active');
		}
	});
	$(current_li).addClass('active');
	close_screen_loader_ajax(layer_idname);
}

function show_screen_loader_ajax(classname_blockgame, id){
	var width	=	$('.' + classname_blockgame).width();
	var height	=	$('.' + classname_blockgame).height();
	var offset	=	$('.' + classname_blockgame).offset();
		
	var html	=	'<div class="ajax_loader_layer" id="'+ id + '"><img src="images/input-loading.gif" /></div>';
	$('body').append(html);
	$('#' + id).find('img').css({
		'left': (width/2) - 12,
		'top': (height/2) - 12
	});
	$('#' + id).css({
		'width' : width,
		'height' : height,
		'display': 'block',
		'left': offset.left,
		'top': offset.top
	});
}
function close_screen_loader_ajax(id){
	$('#' + id).remove();
}

window.onload = function(){
	$(document).ready(function(){
		if($('.top-game .list-game').attr('class')){
            auto_slideshow_hotgame();
        }
	});
};